package team.seekers.hula.course.structure.chapter.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team.seekers.hula.course.resource.exam.service.ExamManageService;
import team.seekers.hula.course.structure.chapter.dao.ChapterDao;
import team.seekers.hula.course.structure.chapter.entity.dao.ChapterDO;
import team.seekers.hula.course.structure.chapter.entity.dto.ChapterManageDTO;
import team.seekers.hula.course.structure.chapter.entity.dto.ChapterQueryListDTO;
import team.seekers.hula.course.structure.section.service.SectionManageService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * date: 2022/5/6 16:35
 *
 * @author GH
 * QQ 1124813753
 */
@Service
public class ChapterManageService {

    @Autowired
    private ChapterDao chapterDao;

    @Autowired
    private SectionManageService sectionManageService;

    @Autowired
    private ExamManageService examManageService;

    @Transactional(rollbackFor = Exception.class)
    public void save(ChapterManageDTO reqDTO) {
        ChapterDO chapterDO = ChapterDO.fromDTO(reqDTO);
        chapterDao.save(chapterDO);
    }

    public void update(ChapterManageDTO reqDTO) {
        chapterDao.updateById(ChapterDO.fromDTO(reqDTO));
    }

//    public List<ChapterQueryListDTO> getDetailCourseDirsByCourseId(Long courseId) {
//        List<ChapterManageDTO> chapterDTOS = ChapterDO.toDTOs(chapterDao.lambdaQuery()
//                .eq(ChapterDO::getCourseId, courseId).list());
//
//        return chapterDTOS.stream().map(chapterDTO ->
//                ChapterQueryListDTO.builder()
//                        .id(chapterDTO.getId())
//                        .name(chapterDTO.getName())
//                        .exams(examManageService.queryDetailCourseExamsByChapterId(chapterDTO.getId()))
//                        .sections(sectionManageService.queryDetailSectionsByChapterId(chapterDTO.getId()))
//                        .build()).collect(Collectors.toList());
//    }




//    @Transactional(rollbackFor = Exception.class)
//    public void delete(Long chapterId, CourseManageDTO courseManageDTO) {
//        chapterDao.removeById(chapterId);
//        courseManageService.updateCourse(courseManageDTO);
//    }
}
